import { FunctionComponent } from 'react';
import { IRoutes } from '@todo/core';

export function findSegment(
  obj: IRoutes,
  item: Array<string>,
  result: Array<string> = [],
): FunctionComponent | undefined {
  for (const key in obj) {
    if (item[0] === obj[key].name) {
      if (obj[key].children && obj[key].children?.length && item.length > 1) {
        return findSegment(obj[key].children || [], item.slice(1), result);
      } else {
        return obj[key].pageComponent;
      }
    }
  }
}
